package models

import (
	"server/basic/config"
	"time"
)

type Goods struct {
	Id          uint      `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	GoodsName   string    `gorm:"column:goods_name;type:varchar(255);comment:商品名称;not null;" json:"goods_name"`                   // 商品名称
	GoodsDesc   string    `gorm:"column:goods_desc;type:varchar(255);comment:商品描述;not null;" json:"goods_desc"`                   // 商品描述
	GoodsPrice  uint      `gorm:"column:goods_price;type:int UNSIGNED;comment:商品价格;not null;default:0;" json:"goods_price"`       // 商品价格
	GoodsWeight uint      `gorm:"column:goods_weight;type:int UNSIGNED;comment:商品重量（kg）;not null;default:0;" json:"goods_weight"` // 商品重量（kg）
	GoodsImage  string    `gorm:"column:goods_image;type:varchar(255);comment:商品图片;not null;" json:"goods_image"`                 // 商品图片
	GoodsStock  uint      `gorm:"column:goods_stock;type:int;comment:商品库存;not null;" json:"goods_stock"`                          // 商品库存
	CreatedAt   time.Time `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (g *Goods) TableName() string {
	return "goods"
}
func (g *Goods) GetGoodsDetail() error {
	return config.DB.Where("id = ?", g.Id).Find(&g).Error
}
func (g *Goods) GetGoodsList() (goodsList []*Goods, err error) {
	err = config.DB.Where("goods_name = ?", g.GoodsName).Find(&goodsList).Error
	return
}
